package ps.client.plugin.eq2.log;


public class LogReaderStatus extends Thread {
    
    private static final int TIME_OUT_DELAY = 60000;
    
    private static final int STATE_NONE = 0;
    private static final int STATE_TIMED_OUT = 1;
    private static final int STATE_ACTIVE = 2;
    
    boolean running = true;
    
    int state = STATE_NONE;
    
    private LogReader logReader;
    
    public LogReaderStatus(LogReader logReader) {
        super("LogReaderStatus");
        this.logReader = logReader;
        
        setDaemon(true);
    }
    
    @Override
    public void run() {
        try {
            while (running) {
                if (System.currentTimeMillis() - logReader.getLastRead() > TIME_OUT_DELAY) {
                    if (state != STATE_TIMED_OUT) {
                        state = STATE_TIMED_OUT;
                        fireLogReadingTimedOut();
                    }
                } else {
                    if (state != STATE_ACTIVE) {
                        state = STATE_ACTIVE;
                        fireLogReadingActive();
                    }
                }
                Thread.sleep(1000);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    public boolean isActive() {
        return state == STATE_ACTIVE;
    }
    
    public void stopLogReaderStatus() {
        running = false;
    }
    
    protected void fireLogReadingActive() {
    }
    
    protected void fireLogReadingTimedOut() {
    }

}
